﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ComBLL;
using System.IO;
using ComModel;

namespace ForumUI.Controllers
{
    public class RegisterController : Controller
    {
        //
        // GET: /Default1/
        registerLogin_bll bll = new registerLogin_bll();
        public ActionResult Login()
        {
           return View();
        }
        public ActionResult LoginDo() //登陆验证
        {
           string name= Request["name"];
           string pwd= Request["pwd"];
            if (bll.Login(name, pwd) > 0)
            {
                return Content("<script>alert('登录成功!');location.href='/xian/index'</script>");
            }
            else
            {
                return Content("<script>alert('账号密码不正确!');</script>");
            }
        }
        public ActionResult Register()//注册主页
        {
            return View();
        }
        public int RegisterDo(HttpPostedFileBase File1)//注册验证
        {

            string filename = Path.Combine(Request.MapPath("~/ImageHead"), Path.GetFileName(File1.FileName));
            File1.SaveAs(filename);
            if(filename=="")
            {
                return 1;
            }
            UserModel user = new UserModel();
            user.user_name = Request["name"];
            user.user_password = Request["pwd"];
            user.user_face = filename;
            user.user_sex = Request["sex"];
            user.user_phone = Request["phone"];
            user.user_email = Request["email"];
            user.user_regTime=DateTime.Now;
            if (bll.Register(user) > 0)
            {
                return 2;
            }
            else
            {
                return 3;
            }
        }
    }
}
